<!DOCTYPE html>
<html>
<head>
<title>数据库管理</title>
#include("../include/common.html")
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>数据库管理</h5>
            </div>
           	<form id="listForm" action="#(base)/admin/database" method="get">
	            <div class="ibox-content">
	                <!-- 搜索 start -->
	                <!-- 搜索 end -->
	                <!-- 列表 start -->
	                <div class="form-horizontal clear">
	                    <div class="form-group">
	                        <div class="col-sm-8">
	                            <a class="btn btn-primary" href="javascript:;" id="backup"><i class="fa fa-plus"></i> 备份</a>
	                            <a href="javascript:;" class="btn btn-primary" id="refreshButton"><i class="fa fa-refresh"></i> 刷新</a>
	                        </div>
	                    </div>
	                    <div class="table-responsive">
	                        <table class="table table-bordered" id="listTable">
	                            <thead>
	                                <tr>
	                                    <th>名称</th>
	                                    <th>操作</th>
	                                </tr>
	                            </thead>
	                            <tbody>
	                            	#for(backup : backups)
	                                <tr>
	                                    <td>#(backup)</td>
	                                    <td>
	                                        <a href="javascript:;" class="restore" val="#(backup)">[还原]</a>
	                                        <a href="javascript:;" class="delete" val="#(backup)">[删除]</a>
	                                    </td>
	                                </tr>
	                                #end
	                            </tbody>
	                        </table>
	                    </div>
	                    <div class="text-center">
	                    </div>
	                </div>
	                <!-- 列表 end -->
	            </div>
            </form>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
$().ready(function() {

    var $backup = $("#backup");
    //备份
    $backup.click(function() {
    	swal({title:'', text:'正在备份中',icon: 'info' ,button:false});
        $.ajax({
            url: "#(base)/admin/database/backup",
            type: "POST",
            data: {},
            dataType: "json",
            cache: false,
            success: function(response) {
            	if(response.type=="success"){
            		swal({title:'', text:'备份完成',icon: 'success' }).then(function() {
                        location.reload();
                    });
            	}else{
            		swal({title:'', text:response.msg,icon: 'error' });
            	}
            }
        });
        return false;
    });
    
    //还原
    $(".restore").on("click",function(){
    	var $this = $(this);
    	var name = $this.attr("val");
    	swal({title:'', text:'正在还原中',icon: 'info' ,button:false});
        $.ajax({
            url: "#(base)/admin/database/restore",
            type: "POST",
            data: {name:name},
            dataType: "json",
            cache: false,
            success: function(response) {
            	if(response.type=="success"){
                    swal({title:'', text:'还原完成',icon: 'success' });
                }else{
                    swal({title:'', text:response.msg,icon: 'error' });
                }
            }
        });
        return false;
    });
    
    //删除
    $(".delete").on("click",function(){
        var $this = $(this);
        var name = $this.attr("val");
        $.ajax({
            url: "#(base)/admin/database/delete",
            type: "POST",
            data: {name:name},
            dataType: "json",
            cache: false,
            success: function(response) {
                if(response.type=="success"){
                	swal({title:'', text:'操作成功',icon: 'success' }).then(function() {
                        location.reload();
                    });
                }else{
                    swal({title:'', text:response.msg,icon: 'error' });
                }
            }
        });
        return false;
    });

});
</script>